<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="root">
        <h2>{{name}}</h2>
        <h2>当前的n值是<span v-text="n"></span></h2>
        <h2>放大10倍的n值是<span v-big-number="n"></span></h2>
        <button @click="n++">n+1</button>
        <input type="text" v-fbind:value="n"> <!-- autofocus在input里获取焦点 -->
    </div>
    <script src="vue.js"></script>
    <script>
        Vue.config.productionTip = false
        //全局的自定义指令
        Vue.directive('big',function(element, binding){
            console.log(element, binding);
            element.innerText = binding.value * 10
        })
        Vue.directive('fbind', {
            
            bind(element, binding) {
                element.value = binding.value
            },
        
            inserted(element, binding) {
                element.focus()
            },
            
            update(element, binding) {
                element.value = binding.value
                element.focus()
            }
        })
        const vm = new Vue({
            el: '#root',
            data: {
                name: '尚硅谷',
                n: 1
            },
            //都是局部指令而已
            directives:
            {
                //命名方法
                'big-number'(element, binding) {
                    console.log(element, binding);
                    element.innerText = binding.value * 10
                },
               
                fbind:
                {
                    
                    bind(element, binding) {
                        element.value = binding.value
                    },
                    
                    inserted(element, binding) {
                        element.focus()
                    },
                    
                    update(element, binding) {
                        element.value = binding.value
                        element.focus()
                    }
                    
                }
            }
        })
    </script>
</body>

</html>